package com.trace.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


/**
 * 弹出Toast的一个工具类，这里主要是增加了对系统Toast背景的修改
 * 
 * @author Administrator
 * 
 */
public class ToastView {

	/**
	 * 
	 * @param context
	 *            上下文对象
	 * @param msg
	 *            要显示的信息
	 * @param timeTag
	 *            时间参数 若是“s”表示短时间显示 若是“l”（小写L）表示长时间显示
	 */
	public static void toast(Context context, String msg, String timeTag) {
		int time = Toast.LENGTH_SHORT;
		if (timeTag == null || "l".equals(timeTag)) {
			time = Toast.LENGTH_LONG;
		}

		Toast toast = Toast.makeText(context, msg, time);
//		LinearLayout layout = (LinearLayout) toast.getView();
//		layout.setLayoutParams(new LayoutParams(60, 30));
//		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		View  view  =  inflater.inflate(R.layout.toast_custom_view,null);
//		TextView   tv = (TextView) view.findViewById(R.id.tv_toast);
//		tv.setText(msg);
//		toast.setView(view);

//		layout.setBackgroundColor(context.getResources().getColor(R.color.tostview_bg));
////		layout.setBackgroundResource(R.drawable.toast_bg);
//		layout.setOrientation(LinearLayout.HORIZONTAL);
//		layout.setGravity(Gravity.CENTER);
//		TextView tv = new TextView(context);
//		tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
//				LayoutParams.WRAP_CONTENT));
//		tv.setLayoutParams(new LayoutParams(60,
//				30));
//		tv.setGravity(Gravity.CENTER);
//		tv.setTextColor(Color.parseColor("#ffffff"));
//		tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
//		tv.setPadding(15, 0, 15, 0);
//		tv.setText(msg);
//		layout.addView(tv);
		toast.show();
	}

	/**
	 * 默认Toast Time 为 s
	 * @param context
	 * @param msg
     */
	public static void toast(Context context, String msg) {
		toast(context,msg,null);
	}
}